<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;

class Seller extends Authenticatable
{
    use HasApiTokens,Notifiable,HasRoles;

    protected $guard_name = 'seller';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'salt', 'remember_token',
    ];



    public function getSalt()
    {
        return $this->salt;
    }


    /**
     * 通过帐号名查找用户,用于验证validateForPassportPasswordGrant
     * @param $username
     * @return mixed
     */
    public function findForPassport($username)
    {
        $user = $this->where('mobile', '=' , $username)->first();

        return $user;
    }

    /**
     * 验证密码是否正确
     * @param $password
     * @return bool
     */
    public function validateForPassportPasswordGrant($password)
    {
        return bcrypt($password, ['salt'=>$this->getSalt()]) === $this->getAuthPassword();
    }
}
